﻿<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>
		Perform Actions When an E-Mail Message Is Received
	  </Title>
    </Header>
    <Snippet>
      <Code Language="CSharp">
        <![CDATA[
		private void ThisApplication_Startup(object sender, System.EventArgs e)
		{
			this.NewMail += new Microsoft.Office.Interop.
				Outlook.ApplicationEvents_11_NewMailEventHandler(
				ThisApplication_NewMail);
		}

		void ThisApplication_NewMail()
		{
			string filter = "USED CARS";

			Outlook.NameSpace outlookNameSpace = this.GetNamespace("MAPI");
			Outlook.MAPIFolder inbox = outlookNameSpace.GetDefaultFolder(
				Microsoft.Office.Interop.Outlook.
				OlDefaultFolders.olFolderInbox);

			Outlook.Items items = inbox.Items;
			items.Restrict("[Unread] = true");

			// If the mail item matches the specified filter,
			// move it to the junk e-mail folder.
			foreach (Outlook.MailItem mail in items)
			{
				if (mail.MessageClass == "IPM.Note" &&
					mail.Subject.ToUpper().Contains(filter.ToUpper()))
				{
					mail.Move(outlookNameSpace.GetDefaultFolder(
						Microsoft.Office.Interop.Outlook.
						OlDefaultFolders.olFolderJunk));
				}
			}
		}
		]]>
	</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>